﻿/*----------------------------------------------------------------
// Copyright (C) 2011 上海
// 版权所有。 
//
// 文件名：DataAccessConsumptionPeriods
// 文件功能描述：消费时段设置数据访问层
//
// 
// 创建标识：2012-03-23 王冲
//
// 修改标识：
// 修改描述：
//
//
//----------------------------------------------------------------*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using DbAdapter.sqldbAdapter;
using System.Data.SqlClient;

namespace DAO.WaiGaoQiao
{
    public class DataAccessConsumptionPeriods
    {
        /// <summary>
        /// 消费时段数量
        /// </summary>
        /// <returns></returns>
        public int GetConsumptionPeriodsCount()
        {
            sqldb db = new sqldb();
            string query = "select count(1) from Con_Period where PeriodCode in(1,2,3,4)";
            object rowcount = db.ExecuteScalar(GetConntionString.conntionstring(), CommandType.Text, query);
            return Convert.ToInt32(rowcount);
        }

        /// <summary>
        /// 获取消费时段信息
        /// </summary>
        /// <returns></returns>
        public DataSet SelConsumptionPeriodsInfo(int pagesize, int startindex, string strquery)
        {
            using (SqlConnection conn = new SqlConnection(GetConntionString.conntionstring()))
            {
                sqldb db = new sqldb();
                int startrow = pagesize * (startindex - 1);
                int endrow = pagesize * startindex + 1;
                string query = "select * from (select ROW_NUMBER() OVER(ORDER BY PeriodCode ASC) rownumber,PeriodCode,PeriodName,BeginTime,EndTime,case NextDay when 0 then '否' else '是' end NextDay " +
                               "from Con_Period where PeriodCode in(1,2,3,4)) B "
                             + "where B.rownumber > " + startrow.ToString() + " and B.rownumber < " + endrow.ToString() + strquery;
                DataSet ds = db.ExecuteDataset(conn, CommandType.Text, query);
                return ds;
            }
        }

        /// <summary>
        /// 根据编号获取一条消费时段信息
        /// </summary>
        /// <param name="supplierNo"></param>
        /// <returns></returns>
        public DataSet GetConsumptionPeriodsInfoOne(string ID)
        {
            sqldb db = new sqldb();
            string query = "select * from Con_Period where PeriodCode = '" + ID + "'";
            return db.ExecuteDataset(GetConntionString.conntionstring(), CommandType.Text, query);
        }

        /// <summary>
        /// 保存消费时段(修改界面下)
        /// </summary>
        /// <param name="supp"></param>
        /// <returns></returns>
        public int SaveConsumptionPeriodsEdit(object[] obj)
        {
            sqldb db = new sqldb();
            string query = "update Con_Period set BeginTime='" + obj[1] + "',EndTime='" + obj[2] + "',NextDay='" +
                obj[3] + "' where PeriodCode=" + obj[0];
            int rowcount = db.ExecuteNonQuery(GetConntionString.conntionstring(), CommandType.Text, query);
            return rowcount;
        }
    }
}
